package com.lanyou.cook.camel.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.lanyou.cook.camel.commons.Constants;
import com.lanyou.cook.camel.dao.impl.FtpServerDao;
import com.lanyou.cook.camel.datadictionary.FtpHostType;
import com.lanyou.cook.camel.entity.FtpServer;
import com.lanyou.cook.camel.service.FtpServerService;

public class FtpServerServiceImpl implements FtpServerService{

	private FtpServerDao ftpServerDao;
	
	private Map<String,FtpServer> map = new HashMap<String, FtpServer>();
	
	@Override
	public Map<String,FtpServer> getFtpServersByFtpId(String ftpId) {
		System.out.println("getFtpServersByFtpId: " + ftpId);
		// TODO 自动生成的方法存根
		if(StringUtils.isNotBlank(ftpId));{
			if(this.map.isEmpty()){
				List<FtpServer> ftpServers = ftpServerDao.findFtpServersByFtpId(ftpId);
				System.out.println("ftpServers: " + ftpServers.size());
				int i = 1;
				int j = 1;
				for (FtpServer ftpServer : ftpServers) {
					if(StringUtils.equals(FtpHostType.SOURCE_HOST.ValueCode, ftpServer.getHostType())){
						System.out.println("hostType: " + ftpServer.getHostType());
						if(i == 1){
							System.out.println("1");
							this.map.put(Constants.SOURECE_FIRST, ftpServer);
							i = i + 1;
						}else if(i == 2){
							System.out.println("2");
							this.map.put(Constants.SOURECE_SECOND, ftpServer);
							i = i + 1;
						}
						
					}else{
						System.out.println("hostType: " + ftpServer.getHostType());
						if(j == 1){
							System.out.println("3");
							this.map.put(Constants.TARGET_FIRST, ftpServer);
							j = j + 1;
						}else if(j == 2){
							System.out.println("4");
							this.map.put(Constants.TARGET_SECOND, ftpServer);
							j = j + 1;
						}
					}
				}
			}else{
				return this.map;
			}
		}
		System.out.println("map:" + map.get("source_second").getPort());
		return this.map;
	}
	
	
	public FtpServerDao getFtpServerDao() {
		return ftpServerDao;
	}
	public void setFtpServerDao(FtpServerDao ftpServerDao) {
		this.ftpServerDao = ftpServerDao;
	}

}
